package org.awenlice.playerdailyshop.event;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = "playerdailyshop", bus = Mod.EventBusSubscriber.Bus.FORGE)
public class TooltipEventHandler {
    @SubscribeEvent
    public static void onItemTooltip(ItemTooltipEvent event) {
        ItemStack stack = event.getItemStack();

        // 检查物品是否包含自定义提示信息
        if (stack.hasTag() && (stack.getTag().contains("price"))) {
            // 添加价格和生成概率到提示信息
            if (stack.getTag().contains("price")) {
                event.getToolTip().add(Component.literal("价格:" + stack.getOrCreateTag().getInt("price")).withStyle(ChatFormatting.WHITE));
            }
            if (stack.getTag().contains("weight")) {
                String weight = stack.getTag().getString("weight");
                String wS = "稀碎";
                ChatFormatting color = ChatFormatting.DARK_GRAY;
                switch (weight){
                    case "5":
                        color = ChatFormatting.GOLD;
                        wS = "传说";
                        break;
                    case "4":
                        color = ChatFormatting.DARK_PURPLE;
                        wS = "史诗";
                        break;
                    case "3":
                        color = ChatFormatting.BLUE;
                        wS = "罕见";
                        break;
                    case "2":
                        wS = "稀有";
                        color = ChatFormatting.DARK_GREEN;
                        break;
                    case "1":
                        wS = "普通";
                        color = ChatFormatting.WHITE;
                        break;
                }

                event.getToolTip().add(Component.literal("品质:" + wS).withStyle(color));

            }
        }
    }
}


